package net.xi.news.controller;

import net.xi.news.pojo.Video;
import net.xi.news.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author zhangyu
 * 视频控制层
 */
@Controller
@RequestMapping("/video/")
public class VideoController {

    private final VideoService videoService;

    public VideoController(VideoService videoService) {
        this.videoService = videoService;
    }


    @RequestMapping("test")
    public String videoTest(){
        return "video";
    }

    @GetMapping("details/{id}")
    public String videoByDetails(@PathVariable String id,Model model){
        Video video = videoService.getById(id);
        video.setViews(video.getViews()+1);
        videoService.updateById(video);
        model.addAttribute("video",video);
        return "video";
    }
}
